@extends('admin.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("admin.public.left")
        <aside>
            <section class="vbox">
                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="{{url('admin/card')}}">
                        <div class="row m-t-sm">
                            <div class="col-sm-3 m-b-xs">
                                <a role="button" class="btn btn-sm btn-primary excel">导出
                                    <i class="glyphicon"></i>
                                </a>
                                <a role="button" class="btn btn-sm btn-primary sc-opt" href="{{url("admin/product/create")}}">生成
                                    <i class="glyphicon"></i>
                                </a>
                                <a role="button" class="btn btn-sm btn-primary dj-opt" href="{{url("admin/product/create")}}">冻结
                                    <i class="glyphicon"></i>
                                </a>
                            </div>
                            <div class="col-sm-9 m-b-xs">
                                <div class="input-group">
									<select class="input-sm" name="status" style="width: 160px">
										<option value="0" selected=""> 选择状态</option>
										<option value="1" @if( old('status') == 1) selected="selected" @endif > 未激活</option>
										<option value="2" @if( old('status') == 2) selected="selected" @endif > 激活</option>
									</select>
                                    <input class="input-sm" name="keyword" value="{{ old('keyword') }}" placeholder="请输入卡号" type="text">
									<input type="text" name="start_time" value="{{ old('start_time') }}" id="start" placeholder="开始时间">&nbsp—&nbsp
									<input type="text" name="end_time" value="{{ old('end_time') }}" id="end" placeholder="结束时间">
									<span class="input-group-btn">
                                        <button class="btn btn-sm btn-default" type="submit" title="搜索">
                                            <i class="glyphicon glyphicon-search"></i> 搜索
                                        </button>
                                    </span>
                                </div>
                            </div>
                           
                        </div>
                    </form>
                </header>
                <div class="tc-bgg"></div>
                <div class="tc-dv tc-dv-sc">
                	<p>请输入生成数量</p>
                	<div class="clearfix">
                		<span>生成数量:</span>
                		<a class="reduce" id="reduce">-</a>
							<input type="text" name="cardNum" id="cardNum" value="100000">
						<a class="add" id="add">+</a>
                	</div>	
                	<div class="clearfix">
                        <span>生成年份:</span>
                        <select name="yeara">
                        	<option value="0">0</option>
                        	<option value="1">1</option>
                        	<option value="2">2</option>
                        	<option value="3">3</option>
                        	<option value="4">4</option>
							<option value="5">5</option>
							<option value="6">6</option>
							<option value="7">7</option>
							<option value="8">8</option>
							<option value="9">9</option>
                        </select>
						<select name="yearb">
							<option value="0">0</option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
							<option value="6">6</option>
							<option value="7">7</option>
							<option value="8">8</option>
							<option value="9">9</option>
						</select>
                    </div>
					<div class="clearfix">
						<span>绑定规则:</span>
						<select name="function_id" style="width: 130px">
							@foreach($rule as $v)
								<option value="{{$v->id}}">{{$v->name}}</option>
							@endforeach
						</select>
					</div>
                	<p class="opt-btn">
                		<a href="javascript:void(0)" class="qd-btn">确定</a>
                		<a href="javascript:void(0)" class="qx-btn">取消</a>
                	</p>
                </div>
                <div class="tc-dv tc-dv-dc">
                	<p>请输入导出信息</p>
                    <p class="qsjsh">
                        <span>起始号:</span>
                        <input type="text" id="startNum1" name="startNum1">
                    </p>
                    <p class="qsjsh">
                        <span>结束号:</span>
                        <input type="text" id="endNum2" name="endNum2">
                    </p>
                    <p class="opt-btn">
                        <a href="javascript:void(0)" class="dc-btn">导出</a>
                        <a href="javascript:void(0)" class="qx-btn">取消</a>
                    </p>
                </div>
                <div class="tc-dv tc-dv-dj">
                	<p>请输入冻结数量</p>
                	<p class="qsjsh">
                		<span>起始号:</span>
						<input type="text" name="startNum" id="startNum">
                	</p>
                	<p class="qsjsh">
                		<span>结束号:</span>
						<input type="text" name="endNum" id="endNum">
                	</p>	
                	<p class="opt-btn">
                		<a href="javascript:void(0)" class="dj-btn">冻结</a>
                		<a href="javascript:void(0)" class="qx-btn">取消</a>
                	</p>
                </div>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-hover m-b-none entity-view" data-path="/attendance/count/countDetail/id/{0}">
                                <thead>
                                <tr>
                                    <th style="text-align: center;">序号</th>
                                    <th style="text-align: center;">实体卡卡号</th>
                                    <th style="text-align: center;">密码</th>
                                    <th style="text-align: center;">状态</th>
									<th style="text-align: center;">激活时间</th>
                                    <th style="text-align: center;">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach ($res as $k=>$v)
                                    <tr>
                                        <td style="text-align: center;">{{$limit*($res->currentPage()-1)+$k+1}}</td>
                                        <td style="text-align: center;">{{$v->card_num}}</td>
                                        <td style="text-align: center;">{{$v->password}}</td>
                                        <td style="text-align: center;">{{\App\Http\Util\CardStatus::getLabel($v->status)}}</td>
										<td style="text-align: center;">{{\App\Http\Util\TimeHelper::formatDateTime($v->updated_at)}}</td>
                                        <td style="text-align: center">
                                            <?php $active = DB::table('switcheds')->pluck('status');?>
                                            @if($active==2&&$v->status != 2)
                                                <a class="label label-danger unbind-printer act"  data-id="{{$v->id}}" >激活</a>
                                            @endif
											@if($v->status != 3)
                                            <a class="label label-success freeze" data-id="{{$v->id}}">冻结</a>
                                        	@endif
										</td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </section>
                    <div>共&nbsp{{$count}}&nbsp条</div><div style="text-align: center">{!! $res->appends($_GET)->render() !!}</div>
                </section>

            </section>
        </aside>
    </section>

@endsection

@section('addscript')
	<script src="{{ url('/') }}/laydate/laydate.js"></script>
    <script>
		var start = {
			elem: '#start',
			format: 'YYYY-MM-DD',
			max: '2099-06-16', //最大日期
			istime: false,
			istoday: true,
			choose: function(datas){
				end.min = datas; //开始日选好后，重置结束日的最小日期
				end.start = datas //将结束日的初始值设定为开始日
			}
		};
		var end = {
			elem: '#end',
			format: 'YYYY-MM-DD',
			max: '2099-06-16',
			istime: false,
			istoday: true,
			choose: function(datas){
				start.max = datas; //结束日选好后，重置开始日的最大日期
			}
		};
		laydate(start);
		laydate(end);
        $(function(){
			//导出
			$(".excel").click(function() {
				$(".tc-dv-dc,.tc-bgg").show();
			});

			$(".dc-btn").click(function(){
				var startNum = $("#startNum1").val();
				var endNum = $("#endNum2").val();
				if(startNum==''){
					alert("请输入起始号");
					$("#startNum1").focus();
				}
				else if(endNum==''){
					alert("请输入结束号");
					$("#endNum2").focus();
				}
				else{
					window.location.href="card/excel1?start="+startNum+"&end="+endNum;
				}
				
			})

            $(".del").click(function(){
                var url=$(this).attr("data-back");

                layer.confirm('您确定删除吗？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    $.ajax({
                        'url':url,
                        'type':"get",
                        'dataType':'json',
                        'success':function(data){
                            if(data.success){
                                layer.alert("删除成功！",function(){
                                    location.reload();
                                });
                            }else{
                                layer.alert(data.msg)
                            }
                        }
                    })
                }, function(){

                })
            });
            //生成的弹窗 数量增加减少
            $(".sc-opt").click(function(){
            	$(".tc-bgg,.tc-dv-sc").show();	 
            	return false;  
            });
	       var t=$("#cardNum");
			t.keyup(function(){  
				if(t.val().replace(/[^0-9.]/g,'')){
				}else{
					alert("请输入正确的数值！");
					t.val('');
				} 
			});
	    	$("#add").click(function(){
	        	$("#reduce").css("cursor","pointer");
	        	t.val(parseInt(t.val())+1);				
	        });
	        $("#reduce").click(function(){  
	        	$("#reduce").css("cursor","pointer"); 
				t.val(parseInt(t.val())-1);
	        	if(t.val()<=1){
	        		t.val(1);
	        		$("#reduce").css("cursor","not-allowed");    		
	        	}       	
	        });
	        $(".qx-btn,.tc-bgg").click(function(){
	        	$(".tc-bgg,.tc-dv-sc,.tc-dv-dc").hide();	     
	        });
            //冻结的弹窗
            $(".dj-opt").click(function(){
            	$(".tc-bgg,.tc-dv-dj").show();	 
            	return false;  
            });
             $(".qx-btn,.tc-bgg").click(function(){
	        	$(".tc-bgg,.tc-dv-dj").hide();	     
	        })
			$(".qd-btn").click(function(){
				var num = $("#cardNum").val();
				var yeara = $("[name=yeara]").val();
				var yearb = $("[name=yearb]").val();
				var function_id = $("[name=function_id]").val();
				if(confirm("确认生成吗？")) {
					var index = layer.load(1);
					$.ajax({
						url: "{{ url('admin/card/yieldCard1') }}",
						type: "post",
						dataType: "json",
						data: {num: num,yeara:yeara,yearb:yearb,function_id:function_id},
						success: function (data) {
							layer.close(index);
							if (data.success) {
								window.location.href=location.href;
							}
							else {
								layer.alert(data.msg);
							}
						}
					})
				}
			})
			$(".dj-btn").click(function(){
				var startNum = $("#startNum").val();
				var endNum = $("#endNum").val();
				if(confirm("确认冻结吗？")) {
					$.ajax({
						url: "{{ url('admin/card/freeze') }}",
						type: "post",
						dataType: "json",
						data: {startNum: startNum,endNum:endNum},
						success: function (data) {
							if (data.success) {
								window.location.href=location.href;
							}
							else {
								layer.alert(data.msg);
							}
						}
					})
				}
			})
			$(".act").click(function(){
				var id = $(this).data('id');
				$.ajax({
					url: "{{ url('admin/card/active') }}",
					type: "post",
					dataType: "json",
					data: {id:id},
					success: function (data) {
						if (data.success) {
							window.location.href=location.href;
						}
						else {
							layer.alert(data.msg);
						}
					}
				})
			})
			$(".freeze").click(function(){
				var id = $(this).data('id');
				$.ajax({
					url: "{{ url('admin/card/freezeOnly') }}",
					type: "post",
					dataType: "json",
					data: {id:id},
					success: function (data) {
						if (data.success) {
							window.location.href=location.href;
						}
						else {
							layer.alert(data.msg);
						}
					}
				})
			})
        });
    </script>
	<style>
		.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
		.clearfix{zoom:1;}
		.tc-bgg{
			position: fixed;
			top: 0px;
			left: 0px;
			width: 100%;
			height: 100%;
			background: black;
			opacity: 0.5;
			filter:alpha(opacity=50);
			-moz-opacity:0.5;
			-khtml-opacity: 0.5;
			z-index: 10;
			display: none;
		}
		.tc-dv{
			width: 400px;
			height: 290px;
			position: fixed;
			top: 50%;
			margin-top: -145px;
			left: 50%;
			margin-left: -200px;
			background: white;
			padding: 30px;
			z-index: 11;
			font-size: 16px;
		}
		.tc-dv-sc,.tc-dv-dj,.tc-dv-dc{
			display: none;
		}
		.tc-dv div {
			margin: 25px 0px;
			font-size: 16px;
		}
		.tc-dv div span{
			float: left;
			position: relative;
			top: 7px;
			margin-right: 15px;
		}
		.tc-dv div a{
			text-align: center;
			display: inline-block;
			width: 30px;
			height: 28px;
			cursor: pointer;
			line-height: 28px;
			font-size: 20px;
			color: #999999;
			border: 1px solid #999999;
			background: #f6f6f6;
			margin: 0px;
			padding: 0px;
			float: left;
		}
		.tc-dv div input{
			background: white;
			border-top: 1px solid #999999;
			border-bottom: 1px solid #999999;
			border-left: 0px;
			border-right: 0px;
			min-width: 30px;
			max-width: 70px;
			height: 28px;
			line-height: 28px;
			text-align: center;
			float: left;
		}
		.tc-dv .opt-btn{
			text-align: center;
		}
		.tc-dv .opt-btn a{
			background: #f2f4f4;
			color: #333333;
			padding: 5px 20px;
			border-radius: 4px;
			margin-right: 10px;
		}
		.tc-dv-dj .qsjsh{
			margin: 20px 0px;
		}
		.tc-dv-dj input{
			width: 100px;
			margin-left: 20px;
			border: 1px solid #e3e3e3;
			height: 25px;
			line-height: 25px;
			padding-left: 5px;
			border-radius: 4px;
		}
		.tc-dv-dj .opt-btn {
			text-align: center;
			margin-top: 25px;
		}
		 .tc-dv div select{
        	height: 28px;
        }
	</style>
@endsection
